﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
namespace Website
{
    public partial class UpdateProduct : System.Web.UI.Page
    {
        protected System.Data.DataTable dt;
        
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected void ButtonSua_Click(object sender, EventArgs e)
        {

            ProductsDTO prodDTO = new ProductsDTO();

            prodDTO.ProductID = int.Parse(HiddenFieldProductID.Value);
            prodDTO.ProductName = txt_Product.Text;
            prodDTO.CategoryID = int.Parse(sbCategories.SelectedValue);
            prodDTO.QualityPerUnit = txt_Unit.Text;
            prodDTO.UnitPrice = float.Parse(txt_Price.Text);

            prodDTO.Description = CKEditor1.Text;
            prodDTO.Discount = float.Parse(txt_Discount.Text);

            if (FileUploadImage.HasFile)
            {
                try
                {
                   
                    string filename = System.IO.Path.GetFileName(FileUploadImage.FileName);
                    FileUploadImage.SaveAs(Server.MapPath("~/images/Products/") + filename);
                    prodDTO.Image = FileUploadImage.FileName;

                    StatusLabel.Style.Add("color", "green");
                    new BUS.ProductsBUS().Update(prodDTO);
                    StatusLabel.Text = "Sửa thành công";
                    Response.Redirect("ManageProduct.aspx");
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Sửa không thành công" + ex.Message;
                    StatusLabel.Style.Add("color", "red");
                }
            }
            else // ko sua hinh
            {
                StatusLabel.Style.Add("color", "green");
                new BUS.ProductsBUS().Update(prodDTO);
                StatusLabel.Text = "Sửa thành công";
                Response.Redirect("ManageProduct.aspx");
                
            }
        }
    }
}